﻿using MediatR;
using ProductionManagement.Application.Command.SendWorkersForQualityInspectionCommand;
using ProductionManagement.Infrstructre.lnterface;

namespace ProductionManagement.Application.CommandHandler.SendWorkersForQualityInspectionCommandHandlers
{
    public class SendWorkersForQualityInspectionDeleteCommandHandlers : IRequestHandler<SendWorkersForQualityInspectionDeleteCommand, int>
    {
        private readonly ISendWorkersForQualityInspectionRepository repository;

        public SendWorkersForQualityInspectionDeleteCommandHandlers(ISendWorkersForQualityInspectionRepository repository)
        {
            this.repository = repository;
        }

        public async Task<int> Handle(SendWorkersForQualityInspectionDeleteCommand request, CancellationToken cancellationToken)
        {
            foreach (var item in request.ids)
            {
                var newlist = (await repository.GetAll()).First(x => x.SendWorkersForQualityInspectionId == item);
                newlist.IsDel = true;
                newlist.DelName = request.Dname;
                newlist.DelTime = DateTime.Now;
                await repository.UpdAsync(newlist);
            }
            return 1;
        }
    }
}
